// eslint-disable-next-line
import { UserLayout, BasicLayout, BlankLayout } from '@/layouts'
// import { bxAnaalyse } from '@/core/icons'
// import storage from 'store'

const RouteView = {
  name: 'RouteView',
  render: h => h('router-view')
}

export const asyncRouterMap = (_menu) => {
  const menu = _menu || []
  const baseRouters =
    [
      {
        path: '/',
        name: 'index',
        component: BasicLayout,
        meta: { title: 'menu.home' },
        redirect: '/account/center'
      },
      {
        path: '*',
        redirect: '/404',
        hidden: true
      }
    ]
  const routers = [
    menu && menu.indexOf('ROLE_cat:user') !== -1 && {
      path: '/staff',
      name: 'staff',
      component: RouteView,
      redirect: '/staff/staffList',
      meta: { title: '员工管理', icon: 'user' },
      children: [
        menu && menu.indexOf('ROLE_page:user') !== -1 && {
          path: '/staff/staffList',
          name: 'staffList',
          component: () => import('@/views/staff/StaffList'),
          meta: { title: '员工列表', keepAlive: true }
        }
      ]
    },
    // customer
    menu && menu.indexOf('ROLE_cat:customer') !== -1 && {
      path: '/customer',
      name: 'customer',
      component: RouteView,
      redirect: '/customer/customerList',
      meta: { title: '客户管理', icon: 'team' },
      children: [
        menu && menu.indexOf('ROLE_page:customer') !== -1 && {
          path: '/customer/customerList',
          name: 'customerList',
          component: () => import('@/views/customer/CusotmerList'),
          meta: { title: '客户列表', keepAlive: true }
        }
      ]
    },
    // supplier
    menu && menu.indexOf('ROLE_cat:supplier') !== -1 && {
      path: '/supplier',
      name: 'supplier',
      component: RouteView,
      redirect: '/supplier/supplierList',
      meta: { title: '供应商管理', icon: 'shop' },
      children: [
        menu && menu.indexOf('ROLE_page:supplier') !== -1 && {
          path: '/supplier/supplierList',
          name: 'supplierList',
          component: () => import('@/views/supplier/Supplier'),
          meta: { title: '供应商列表', keepAlive: true }
        },
        menu && menu.indexOf('ROLE_page:product') !== -1 && {
          path: '/supplier/productList',
          name: 'productList',
          component: () => import('@/views/product/Product'),
          meta: { title: '产品列表', keepAlive: true }
        }
      ]
    },
    // expressage
    menu && menu.indexOf('ROLE_cat:express') !== -1 && {
      path: '/expressage',
      name: 'expressage',
      component: RouteView,
      redirect: '/expressage/expressageList',
      meta: { title: '快递管理', icon: 'inbox' },
      children: [
        menu && menu.indexOf('ROLE_page:express') !== -1 && {
          path: '/expressage/expressageList',
          name: 'expressageList',
          component: () => import('@/views/expressage/ExpressageList'),
          meta: { title: '快递列表', keepAlive: true }
        }
      ]
    },
    // project todo 灰度路由
    // menu && menu.indexOf('ROLE_cat:project') !== -1 &&
    menu && menu.indexOf('ROLE_cat:project') !== -1 && {
      path: '/project',
      name: 'project',
      component: RouteView,
      redirect: '/project/projectList',
      meta: { title: '项目管理', icon: 'project' },
      children: [
        menu && menu.indexOf('ROLE_page:project') !== -1 &&
        {
          path: '/project/projectList',
          name: 'projectList',
          component: () => import('@/views/project/ProjectList'),
          meta: { title: '项目列表', keepAlive: true }
        },
        menu && menu.indexOf('ROLE_page:projectInfo') !== -1 && {
          path: '/project/projectInfo',
          name: 'projectInfo',
          hidden: true,
          component: () => import('@/views/project/ProjectInfo'),
          meta: { title: '项目详情', keepAlive: true }
        },
        menu && menu.indexOf('ROLE_but:projectType') !== -1 &&
        {
          path: '/project/projectTypeList',
          name: 'projectTypeList',
          component: () => import('@/views/projectType/ProjectType'),
          meta: { title: '项目类型', keepAlive: true }
        }
      ]
    },
    // contract
    menu && menu.indexOf('ROLE_cat:contract') !== -1 && {
      path: '/contract',
      name: 'contract',
      component: RouteView,
      redirect: '/contract/contractList',
      meta: { title: '合同管理', icon: 'book' },
      children: [
        menu && menu.indexOf('ROLE_page:contract') !== -1 &&
        {
          path: '/contract/contractList',
          name: 'contractList',
          component: () => import('@/views/contract/ContractList'),
          meta: { title: '合同列表', keepAlive: true }
        },
        menu && menu.indexOf('ROLE_page:contractInfo') !== -1 && {
          name: 'contractInfo',
          path: '/contract/contractInfo',
          hidden: true,
          component: () => import('@/views/contract/ContractInfo'),
          meta: { title: '合同详情', keepAlive: true }
        }
      ]
    },
    // incomeExpenses todo 收支
    menu && menu.indexOf('ROLE_cat:income') !== -1 &&
    {
      path: '/incomeExpenses',
      name: 'incomeExpenses',
      component: RouteView,
      redirect: '/incomeExpenses/incomeExpensesList',
      meta: { title: '收支管理', icon: 'money-collect' },
      children: [
        menu && menu.indexOf('ROLE_page:income') !== -1 &&
        {
          path: '/incomeExpenses/incomeExpensesList',
          name: 'incomeExpensesList',
          component: () => import('@/views/incomeExpenses/IncomeExpenses'),
          meta: { title: '付款方式', keepAlive: true }
        }
      ]
    },
    menu && menu.indexOf('ROLE_cat:info') !== -1 && {
      path: '/infoManage',
      name: 'infoManage',
      component: RouteView,
      redirect: '/infoManage/infoList',
      meta: { title: '信息管理', icon: 'profile' },
      children: [
        menu && menu.indexOf('ROLE_page:info') !== -1 && {
          path: '/infoManage/infoList',
          name: 'infoList',
          component: () => import('@/views/infoManage/InfoList'),
          meta: { title: '信息列表', keepAlive: true }
        }
      ]
    },
    menu && menu.indexOf('ROLE_cat:reward') !== -1 && {
      path: '/rewardManage',
      name: 'rewardManage',
      component: RouteView,
      redirect: '/rewardManage/rewardList',
      meta: { title: '奖惩管理', icon: 'like' },
      children: [
        menu && menu.indexOf('ROLE_page:reward') !== -1 && {
          path: '/rewardManage/rewardList',
          name: 'rewardList',
          component: () => import('@/views/rewardManage/rewardList'),
          meta: { title: '奖惩列表', keepAlive: true }
        }
      ]
    },
    //  toodo 任务 灰度路由
    menu && menu.indexOf('ROLE_cat:task') !== -1 &&
    {
      path: '/taskManage',
      name: 'taskManage',
      component: RouteView,
      redirect: '/taskManage/taskList',
      meta: { title: '任务管理', icon: 'bell' },
      children: [
        menu && menu.indexOf('ROLE_page:task') !== -1 &&
        {
          path: '/taskManage/taskList',
          name: 'taskList',
          component: () => import('@/views/taskManage/taskList'),
          meta: { title: '任务列表', keepAlive: true }
        }
      ]
    },
    menu && menu.indexOf('ROLE_cat:performance') !== -1 &&
    {
      path: '/performance',
      name: 'performance',
      component: RouteView,
      redirect: '/performance/performanceList',
      meta: { title: '绩效管理', icon: 'radar-chart' },
      children: [
        menu && menu.indexOf('ROLE_page:performance') !== -1 && {
          path: '/performance/performanceList',
          name: 'performanceList',
          component: () => import('@/views/performance/performanceList'),
          meta: { title: '绩效列表', keepAlive: true }
        }
      ]
    },
    // permission
    menu && menu.indexOf('ROLE_cat:role') !== -1 && {
      path: '/permission',
      name: 'permission',
      component: RouteView,
      redirect: '/permission/permissionList',
      meta: { title: '权限管理', icon: 'lock' },
      children: [
        menu && menu.indexOf('ROLE_page:role') !== -1 && {
          path: '/permission/permissionList',
          name: 'permissionList',
          component: () => import('@/views/permission/Permission'),
          meta: { title: '权限配置', keepAlive: true }
        }
      ]
    },
    menu && menu.indexOf('ROLE_cat:performanceConfig') !== -1 && {
      path: '/regulation',
      name: 'regulation',
      component: RouteView,
      redirect: '/regulation/RegulationList',
      meta: { title: '规则配置', icon: 'lock' },
      children: [
        menu && menu.indexOf('ROLE_page:performanceConfig') !== -1 && {
          path: '/regulation/RegulationList',
          name: 'RegulationList',
          component: () => import('@/views/regulation/RegulationList'),
          meta: { title: '规则列表', keepAlive: true }
        }
      ]
    },
    menu && menu.indexOf('ROLE_cat:incentiveGrant') !== -1 && {
      path: '/bonus',
      name: 'bonus',
      component: RouteView,
      redirect: '/bonus/BonusList',
      meta: { title: '提成记录', icon: 'book' },
      children: [
        menu && menu.indexOf('ROLE_page:incentiveGrant') !== -1 &&
        {
          path: '/bonus/BonusList',
          name: 'BonusList',
          component: () => import('@/views/bonus/BonusList'),
          meta: { title: '提成记录', keepAlive: true }
        }
      ]
    }
  ]
  const _resRouters = routers.filter(item => { if (item) return item })
  _resRouters.forEach(element => {
    element.children = element.children.filter(item => { if (item) return item })
  })
  baseRouters[0].children = _resRouters
  return baseRouters
}
/**
 * 基础路由
 * @type { *[] }
 */
export const constantRouterMap = [
  {
    path: '/user',
    component: UserLayout,
    redirect: '/user/login',
    hidden: false,
    children: [
      {
        path: 'login',
        name: 'login',
        component: () => import(/* webpackChunkName: "user" */ '@/views/user/Login')
      }
    ]
  },
  /// account/center
  {
    path: '/account',
    name: 'index',
    component: BasicLayout,
    meta: { title: '我的信息' },
    redirect: '/account/center',
    children: [
      {
        path: 'center',
        name: 'center',
        meta: { title: '个人信息' },
        component: () => import(/* webpackChunkName: "user" */ '@/views/account/center')
      }
    ]
  },
  {
    path: '/404',
    component: () => import(/* webpackChunkName: "fail" */ '@/views/exception/404')
  }
]
